<script src="Libraries/js/js.js"></script>

<?php
	include_once('Models/HocPhan.php');
	include_once('Configs/paging.php');
    include_once('Models/HocKiNamHoc.php');
    include_once('Models/HPMoVaoHKNH.php');
    include_once('Models/LopHocPhan.php');
    include_once('Models/ThoiKhoaBieu.php');
?>
<script language="javascript">
    function getValue(id){
        document.capnhatlophp.txtmalophp.value=document.getElementById("malophp" + id).innerHTML;
        document.capnhatlophp.txtkihieu.value=document.getElementById("kihieu" + id).innerHTML;
        document.capnhatlophp.txtsiso.value=document.getElementById("siso" + id).innerHTML;
        document.capnhatlophp.txttuanhoc.value=document.getElementById("tuanhoc" + id).innerHTML;
        document.capnhatlophp.txtmaso.value=document.getElementById("maso" + id).innerHTML;
        showTenCB(document.capnhatlophp.txtmaso.value);
    }
    function disable_enable(){
        //document.capnhatlophp.cbonamhoc.selectedIndex = 0;
        /*if (document.capnhatlophp.cbonamhoc.value == " "){
            document.capnhatlophp.cbohocki.selectedIndex=0
            document.capnhatlophp.cbohocki.disabled = true;
        }
        else document.capnhatlophp.cbohocki.disabled = false;
        if (document.capnhatlophp.cbohocki.value == " "){
            document.capnhatlophp.cbohp.selectedIndex=0
            document.capnhatlophp.cbohp.disabled = true;
        }
        else document.capnhatlophp.cbohp.disabled = false;
        if (document.capnhatlophp.cbohp.value == " "){
            document.capnhatlophp.txtmalophp.value = " ";
            document.capnhatlophp.txtkihieu.value = " ";
            document.capnhatlophp.txttuanhoc.value = " ";
            document.capnhatlophp.txtsiso.value = " ";
            //document.capnhatlophp.txtmalophp.disabled = true;
        }*/
        //else document.capnhatlophp.txtmalophp.disabled = false;
        document.capnhatlophp.cbohocki.selectedIndex=0
        //document.capnhatlophp.cbohocki.value == " "
        //if (document.capnhatlophp.cbohocki.selectedIndex == 0){
             document.capnhatlophp.cbohp.selectedIndex=0;
             //document.capnhatlophp.cbohp.value = " ";
             document.capnhatlophp.txtmalophp.value = " ";
            document.capnhatlophp.txtkihieu.value = " ";
            document.capnhatlophp.txttuanhoc.value = " ";
            document.capnhatlophp.txtsiso.value = " ";
            document.capnhatlophp.txtmaso.value = " ";
            document.capnhatlophp.txttencb.value = " ";
             
        //}
        taoMaLopHP_KH(document.capnhatlophp.cbonamhoc.value,document.capnhatlophp.cbohocki.value,document.capnhatlophp.cbohp.value);
    }
    /*function taoMaLopHP_KH(){
        var namhoc = document.capnhatlophp.cbonamhoc.value;
        
        var hocki = document.capnhatlophp.cbohocki.value;
        var hp = document.capnhatlophp.cbohp.value;
        
        //if (stt.length=1) stt = "0" + stt;
        //if (hocki.length=1) hocki = "0" + hocki;
        //var malophp = mahp + namhoc.substr(2,2) + namhoc.substr(7,2) + hocki + stt;
        //alert (malophp);
        //return malophp;
        //var namhoc = document.capnhatlophp.cbonamhoc.value;
    }*/
    function taoMoi(){
		
        //document.capnhatlophp.cbonamhoc.selectedIndex=0;
        //disable_enable();
        document.capnhatlophp.txtsiso.value = " ";
        document.capnhatlophp.txttuanhoc.value = " ";
        document.capnhatlophp.txtmaso.value = " ";
        document.capnhatlophp.txttencb.value = " ";
        taoMaLopHP_KH(document.capnhatlophp.cbonamhoc.value,document.capnhatlophp.cbohocki.value,document.capnhatlophp.cbohp.value);
        
    }
    //taoMaLopHP_KH(document.capnhatlophp.cbonamhoc.value,document.capnhatlophp.cbohocki.value,document.capnhatlophp.cbohp.value);
    
	//alert(taoMaLopHP("2009-2010","1","CT101","1"));

</script>
<form name="capnhatlophp" method="POST">
<table align="center" class="font" width="800" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td class=main_1><img border="0" src="Libraries/images/tbl_left.gif" width="10" height="25" /></td>
    <td align=center class=main_1>Cập nhật Lớp học phần </td>
    <td class=main_1><p align="right"><img border="0" src="Libraries/images/tbl_right.gif" width="10" height="25" /></p></td>
  </tr>
  <tr bgcolor="#dae9f3">
    <td class="border_1" colspan="3" valign="top">
        
            <table width="100%" border="0" align="center"  >
                <tr>
                    <td width="160" >&nbsp;</td>
                </tr>
                <tr>
                  <td ><table border="0" align="center">
                    <tr>
                      <td>Năm học </td>
                      <td><select name="cbonamhoc" onchange="disable_enable();">
                        <option value=" "></option>
                        <?php
								$hknh = new HocKiNamHoc();
                                $result = $hknh->dsNamHoc();
                                while ($rows=mysql_fetch_array($result)){
                                    echo "<option value='".$rows['namhoc']."'";				
				                    echo ">".$rows['namhoc']."</option>";
                                }
                                
                                ?>
                      </select>
                        <?php  
                            if (isset($_POST['cbonamhoc']))
                            {
				                echo "<script language=\"javascript\">for(var i=0;i<document.capnhatlophp.cbonamhoc.length;i++){if(document.capnhatlophp.cbonamhoc[i].value=='$namhoc'){document.capnhatlophp.cbonamhoc.selectedIndex=i;break;}}</script>";
                            }
                        ?></td>
                      <td>Học kì</td>
                      <td><select name="cbohocki" onchange="showHocPhan(document.capnhatlophp.cbonamhoc.value,this.value);">
                        <option value="0"></option>
                        <option value="1" <?php if ($_POST['cbohocki']==1) echo "selected='selected'"; ?>>1</option>
                        <option value="2" <?php if ($_POST['cbohocki']==2) echo "selected='selected'"; ?>>2</option>
                        <option value="3" <?php if ($_POST['cbohocki']==3) echo "selected='selected'"; ?>>Hè</option>
                      </select>
                        <?php  
                            if (isset($_POST['cbohocki']))
                            {
				                echo "<script language=\"javascript\">document.capnhatlophp.cbohocki.disabled = false;for(var i=0;i<document.capnhatlophp.cbohocki.length;i++){if(document.capnhatlophp.cbohocki[i].value=='$hocki'){document.capnhatlophp.cbohocki.selectedIndex=i;break;}}</script>";
                            }
                        ?></td>
                      <td><table border="0">
                        <tr>
                          <td>Học phần</td>
                          <td><?php  
                            if (isset($_POST['cbohp']))
                            {
                                
                                $hphknh = new HPMoVaoHKNH();
                                $hphknh->setHocKi($hocki);
                                $hphknh->setNamHoc($namhoc);
                                $result = $hphknh->dsHocPhanMoVaoHKNH();
                                echo "<div id='hocphan'>";
                                    echo "<select name='cbohp' onchange='taoMaLopHP_KH(document.capnhatlophp.cbonamhoc.value,document.capnhatlophp.cbohocki.value,this.value);'>";
                                        echo "<option value=' '></option>";
                                        while ($rows = mysql_fetch_array($result)){
                                            echo "<option value='".$rows['mahp']."'>".$rows['tenhp']."</option>";
                                        }
                        
                        
                                    echo "</select>";
                                echo "</div>";
				                echo "<script language=\"javascript\">document.capnhatlophp.cbohp.disabled = false;for(var i=0;i<document.capnhatlophp.cbohp.length;i++){if(document.capnhatlophp.cbohp[i].value=='$mahp'){document.capnhatlophp.cbohp.selectedIndex=i;break;}}</script>";
                            }
                            else{
                                echo "<div id='hocphan'>";
                                    echo "<select name='cbohp'>";
                                        echo "<option value=' '></option>";                                 
                                    echo "</select>";
                                echo "</div>";
                            }
                        ?></td>
                        </tr>
                      </table></td>
                    </tr>
                  </table></td>
                </tr>
                <tr>
                  <td ><table border="0" align="center">
                    <tr>
                      <td>Mã LHP</td>
                      <td><input name="txtmalophp" type="text" size="16" readonly="true"/></td>
                      <td>Kí hiệu</td>
                      <td><input name="txtkihieu" type="text" size="16" readonly="true"/></td>
                      <td>Sĩ số</td>
                      <td><input name="txtsiso" type="text" size="16" /></td>
                    </tr>
                  </table></td>
                </tr>
                <tr>
                  <td ><table border="0" align="center">
                    <tr>
                      <td>Tuần học</td>
                      <td><input name="txttuanhoc" type="text" size="16"></td>
                      <td>MSCB</td>
                      <td><input name="txtmaso" type="text" size="16" onkeyup="showTenCB(this.value);"/></td>
                      <td><table border="0">
                        <tr>
                          <td>Tên CB</td>
                          <td><div id="tencb">
                            <input name="txttencb" type="text" size="20" />
                          </div></td>
                        </tr>
                      </table></td>
                    </tr>
                  </table></td>
                </tr>
                <tr>
           	      <td align="center">
					 <input type="submit" name="btnxem" value="Xem" class="button_1"/>
					 <input type="button" name="btntaomoi" value="Tạo mới" class="button_1" onclick="taoMoi();"/>
                    <input type="submit" name="btnthem" value="Thêm" class="button_1"/>
					<input type="submit" name="btnsua" value="Sửa" class="button_1"/>
					<input type="submit" name="btnxoa" value="Xóa" class="button_1"/>				  </td>
                </tr>
            </table>
       
           

    </td>
  </tr>
</table>
<br />

<p>&nbsp;</p>

 </table>

<p><br />
<?php
if (isset($_POST['btnxem'])){

    echo "<table align='center' class='font' width='700' border='0' cellspacing='0' cellpadding='0'>";
      echo "<tr>";
        echo "<td class='main_1'><img border='0' src='Libraries/images/tbl_left.gif' width='10' height='25' /></td>";
        echo "<td align='center' class='main_1'>Danh sách lớp học phần </td>";
        echo "<td class='main_1'><p align='right'><img border='0' src='Libraries/images/tbl_right.gif' width='10' height='25' /></p></td>";
      echo "</tr>";
    
        echo "<tr >";
        	echo "<td class='border_1' colspan='3' valign='top'>";                                                                     
             $lophp = new LopHocPhan();
             $lophp->setMaLopHP($malophp);
             $lophp->setNamHoc($namhoc);
             $lophp->setHocKi($hocki);
             $lophp->setMaHP($mahp);
             $result = $lophp->dsLopHPMoTrongHKNHCuaHP();
                $i = 0;
                while ($rows = mysql_fetch_array($result))
                {
                       $i++;  
                //echo "<form method='POST'>";                                                      
                    echo "<table width='700' class='border_1' style='border:none' id='tbmain' cellpadding='0' cellspacing='0'>";
                   
                        echo "<tr>";
                            //echo "<td align='left' class='main_3'> Lớp HP: <div id='malophp$i' width='100'>".$rows['malophp']."</div>--Kí hiệu:<div id='kihieu$i'>".$rows['kihieu']."</div>--Sĩ số: <div id='siso$i'>".$rows['siso']."</div>--Tuần học:<div id='tuanhoc$i'>".$rows['tuanhoc']."</div></td>";
                            echo "<td align='left'  bgcolor='#DAE9F3' style='font-weight:bold' width='60'>Lớp HP: </td>";
                            echo "<td align='left' bgcolor='#DAE9F3'><div id='malophp$i'>".$rows['malophp']."</div></td>";
                            //echo "<td align='left' bgcolor='#DAE9F3'><div id='malophp$i'>".$rows['malophp']."</div><input type='hidden' name='hidmalophp' value='".$rows['malophp']."'/><input type='hidden' name='hidsiso' value='".$rows['siso']."'/></td>";
                            echo "<td align='left' bgcolor='#DAE9F3' style='font-weight:bold' width='50'>Kí hiệu: </td>";
                            echo "<td align='left' bgcolor='#DAE9F3'><div id='kihieu$i'>".$rows['kihieu']."</div></td>";
                            echo "<td align='left' bgcolor='#DAE9F3' style='font-weight:bold' width='50'>MSCB: </td>";
                            echo "<td align='left' bgcolor='#DAE9F3'><div id='maso$i'>".$rows['maso']."</div></td>";
                            echo "<td align='left'  bgcolor='#DAE9F3' style='font-weight:bold' width='40'>Sĩ số: </td>";
                            echo "<td align='left' bgcolor='#DAE9F3'><div id='siso$i'>".$rows['siso']."</div></td>";
                            echo "<td align='left' bgcolor='#DAE9F3' style='font-weight:bold' width='70'>Tuần học:</td>";
                            echo "<td align='left' bgcolor='#DAE9F3'><div id='tuanhoc$i'>".$rows['tuanhoc']."</div></td>";
                            echo "<td align='center' width='100'  bgcolor='#DAE9F3' style='font-weight:bold'>Chọn";
                            echo "<input type='radio' name='chkchon' value=$i onClick='getValue(this.value);' >";
                                //echo "<input type='submit' name='btnsualophp' value='Sửa' class='button_1'/>";
                               //echo " <input type='submit' name='btnxoalophp' value='Xóa'  class='button_1'/>";
                                //echo "<input name='btncapnhattkb' type='submit'  class='button_1' id='btncapnhattkb' value='Cập nhật TKB'/>";
                            echo "</td>";
                           
                        echo "</tr>";
                        echo "<tr bgcolor='#FFFFFF'>";
                            echo "<td align='center' colspan='11'><table width='400' border='0' class='border_1'>";
                              echo "<tr>";
                                echo "<td colspan='4' align='center' style='font-size: 18'><b>Thời Khóa Biểu</b> </td>";
                              echo "</tr>";
                              $tkb = new ThoiKhoaBieu();
                              $tkb->setMaLopHP($rows['malophp']);
                              $resulttkb = $tkb->thoiKhoaBieuLopHP();
                              $numtkb = mysql_num_rows($resulttkb);
                              if ($numtkb > 0){
                              echo "<tr>";
                                echo "<td width='30' align='center'><b>Thứ</b></td>";
                                echo "<td width='60' align='center'><b>Tiết BĐ</b></td>";
                                echo "<td width='60' align='center'><b>Số Tiết</b></td>";
                                echo "<td width='60' align='center'><b>Phòng</b></td>";
                                
                              echo "</tr>";
                             
                              while ($rowstkb = mysql_fetch_array($resulttkb)){
                              echo "<tr>";
                                echo "<td align='center'>".$rowstkb['thu']."</td>";
                                echo "<td width='60' align='center'>".$rowstkb['tietbd']."</td>";
                                echo "<td width='60' align='center'>".$rowstkb['sotiet']."</td>";
                                echo "<td width='60' align='center'>".$rowstkb['maphong']."</td>";
                                
                              echo "</tr>";
                              }
                              }
                              else{
                              echo "<tr>";
                                echo "<td width='30' align='center' colspan='4'><b>Chưa sắp Thời khóa biểu</b></td>";
                                
                                
                              echo "</tr>";
                              }
                              echo "<tr>";
                                echo "<td align='center'  colspan='4'>";
                                    //echo "<input type='submit' name='btncapnhattkb'  value='Cập nhật TKB' class='button_1'>";
                                    echo "<a href='index.php?option=capnhattkb&malophp=".$rows['malophp']."&siso=".$rows['siso']."'>";
                                    //echo "<a href='index.php?option=capnhatlophp&malophp=".$rows['malophp']."&siso=".$rows['siso']."'>";
                                    
                                    echo "<input type='button' name='btncapnhattkb'  value='Cập nhật TKB' class='button_1'>";
                                    echo "</a>";
                                echo "</td>";
                               
                                
                              echo "</tr>";
                            echo "</table> ";                   
                            echo "</td>";
                            
                        echo "</tr>";
                        
                        
                    echo "</table>";
                    //echo "</form>";
                }
                
            echo "</td>";
     echo " </tr>";
     echo "<tr>";
        $num = mysql_num_rows($result);
        echo "<td  align='left' class='main_3' colspan='9'  style='color:#FF0000'>Tổng số lớp học phần:". $num;
        echo "</td>";
     echo "</tr>"; 
    echo "</table>";
}
/*if (isset($_POST['btncapnhattkb'])){
    require('Views/Capnhatthoikhoabieu.php');
}*/
?> 
 
</p>
<!--<div id="table"></div><--!>
</form>
<p>&nbsp;</p>
<p>&nbsp;</p>
